/*----------------------------MegaWave2 module----------------------------*/
/* mwcommand
name = {cmviews};
version = {"1.0"};
author = {"Baptiste Coulange"};
function = {"Cree une fmovie ou les images des deux fmovie sont l'une à coté de l'autre"};
usage = {
in1->in1           "input image 1",
in2->in2           "input image 2",
out<-out         "output Fimage"
};
*/
/*----------------------------------------------------------------------
v1.0 (04/2007): initial version
----------------------------------------------------------------------*/

#include <stdio.h>
#include <math.h>
#include "mw.h"

Fimage cmviews(in1,in2,out)
   Fmovie in1,in2,out;

{
	Fimage locG,loc1,loc2,prev;
	int x,y,nx,ny,ny2;
	
	nx=(in1->first)->nrow;
	ny=(in1->first)->ncol;
	ny2=(in2->first)->ncol;
	out=mw_change_fmovie(out);
	locG=mw_change_fimage(NULL,nx,ny+ny2);
	prev=mw_change_fimage(NULL,nx,ny+ny2);	
	
	loc1=in1->first;
	loc2=in2->first;

	for(x=0;x<nx;x++)
			for(y=0;y<(ny+ny2);y++) {		
				if(y<ny){locG->gray[x*(ny+ny2)+y]=loc1->gray[x*ny+y%ny];
					} else {
						locG->gray[x*(ny+ny2)+y]=loc2->gray[x*ny2+y%ny];
				}			
			}
	out->first=locG;
	prev=locG;
	

	while(loc1->next){
		locG=mw_change_fimage(NULL,nx,ny+ny2);
		loc1=loc1->next;
		loc2=loc2->next;
	

		
		for(x=0;x<nx;x++)
			for(y=0;y<(ny+ny2);y++) {
				if(y<ny){locG->gray[x*(ny+ny2)+y]=loc1->gray[x*ny+y%ny];
					} else {
						locG->gray[x*(ny+ny2)+y]=loc2->gray[x*ny2+y%ny];
				}
		}
		prev->next=locG;
		locG->previous=prev;
		prev=locG;
			
			
	}
}


